<?php

namespace app\models;

use yii\helpers\ArrayHelper;

class Options
{
    /** Project */
    const ProjectNormal = 0;
    const ProjectClosed = 1;
    public static function projectStates()
    {
        return [
            self::ProjectNormal => '正常',
            self::ProjectClosed => '关闭',
        ];
    }

    /** Issue.state */
    const IssueCollected = 0;
    const IssueWorking  = 1;
    const IssueSuspend  = 2;
    const IssueFinished = 3;
    const IssueDeleted  = 10;
    public static function issueStates(bool $searchMode = false)
    {
        $options = [
            self::IssueCollected    => '收集',
            self::IssueWorking      => '工作中',
            self::IssueSuspend      => '暂停',
            self::IssueFinished     => '完成',
            self::IssueDeleted      => '已删除',
        ];

        return static::checkSearchMode($options, $searchMode, '所有状态');
    }

    const IssueNormal   = 0;
    const IssueMedium   = 1;
    const IssueHighest  = 2;
    public static function issuePriorities(bool $searchMode = false){
        $options = [
            self::IssueNormal => '⭐️',
            self::IssueMedium => '⭐️⭐️',
            self::IssueHighest => '⭐️⭐️⭐️',
        ];

        return static::checkSearchMode($options, $searchMode, '所有级别');
    }

    /** Contact */
    const ContactSrcWeChat  = 0;
    public static function contactSources(){
        return [
            self::ContactSrcWeChat => '微信',
        ];
    }

    public static function projectOptions(){
        return ArrayHelper::map(Project::find()->all(), 'id', 'name');
    }

    public static function contactOptions(){
        return ArrayHelper::map(Contact::find()->all(), 'id', 'name');
    }

    /** Common Functions */

    public static function checkSearchMode($options, $searchMode, $searchAllMsg){
        if($searchMode === true){
            $options = array_merge([null => $searchAllMsg], $options);
        }

        return $options;
    }
}
